DefaultStatesMachine

open class DefaultStatesMachine<T : State>(statesManager: StatesManager<T>, handlers: List<CheckableHandlerHolder<in T, T>>, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler()) : StatesMachine<T>

Default realization of StatesMachine. It uses statesManager for incapsulation of States storing and contexts resolving, and uses launchStateHandling for State handling.

This class suppose to be extended in case you wish some custom behaviour inside of launchStateHandling, for example

Constructors

Link copied to clipboard
fun <T : State> DefaultStatesMachine(statesManager: StatesManager<T>, handlers: List<CheckableHandlerHolder<in T, T>>, onStateHandlingErrorHandler: StateHandlingErrorHandler<T> = defaultStateHandlingErrorHandler())

Functions

Link copied to clipboard
open suspend override fun StatesMachine<in T>.handleState(state: T): T?

Will call launchStateHandling for state handling

Link copied to clipboard
open suspend override fun launchStateHandling(state: T, handlers: List<CheckableHandlerHolder<in T, T>>): T?
open suspend fun launchStateHandling(state: T, handlers: List<CheckableHandlerHolder<in T, T>>, onStateHandlingErrorHandler: StateHandlingErrorHandler<T>): T?
Link copied to clipboard
open suspend fun performStateUpdate(previousState: Optional<T>, actualState: T, scope: CoroutineScope)
Link copied to clipboard
open override fun start(scope: CoroutineScope): Job

Launch handling of states. On statesManager, statesManager will be called lambda with performing of state. If launchStateHandling will returns some State then statesManager will be used, otherwise StatesManager.endChain.

Link copied to clipboard
open suspend override fun startChain(state: T)

Just calls StatesManager.startChain of statesManager

Inheritors

DefaultUpdatableStatesMachine
Link copied to clipboard

Extensions

holder
Link copied to clipboard
inline fun <I : O, O : State> StatesHandler<I, O>.holder(strict: Boolean = true): CustomizableHandlerHolder<O, O>
inline fun <I : O, O : State> StatesHandler<I, O>.holder(noinline filter: suspend (state: State) -> Boolean): CustomizableHandlerHolder<O, O>
inline fun <I : O, O : State> StatesHandler<I, O>.holder(strict: Boolean = true): CustomizableHandlerHolder<O, O>
inline fun <I : O, O : State> StatesHandler<I, O>.holder(noinline filter: suspend (state: State) -> Boolean): CustomizableHandlerHolder<O, O>
inline fun <I : O, O : State> StatesHandler<I, O>.holder(strict: Boolean = true): CustomizableHandlerHolder<O, O>
inline fun <I : O, O : State> StatesHandler<I, O>.holder(noinline filter: suspend (state: State) -> Boolean): CustomizableHandlerHolder<O, O>